//
//  AppDelegate.m
//  LBSCar
//
//  Created by dlios on 15/5/21.
//  Copyright (c) 2015年 lyz. All rights reserved.
//

#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

- (void)dealloc
{
    [_window release];
    [super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
    //创建可变数组 存放四个导航控制器
    NSMutableArray *array = [NSMutableArray array];
    
    //创建首页视图控制器
    FirstPageViewController *firstPage = [[FirstPageViewController alloc] init];
    //创建首页导航控制器
    UINavigationController *firstPageNavigation = [[UINavigationController alloc] initWithRootViewController:firstPage];
    //创建首页tabBar的文字和图片
    firstPageNavigation.tabBarItem = [[[UITabBarItem alloc] autorelease] initWithTitle:@"首页" image:nil selectedImage:nil];
    //添加首页导航控制器到数组
    [array addObject:firstPageNavigation];
    // release
    [firstPage release];
    [firstPageNavigation release];
    
    //创建杂志页视图控制器
    JournalViewController *journal = [[JournalViewController alloc] init];
    UINavigationController *journalNavigation = [[UINavigationController alloc] initWithRootViewController:journal];
    journalNavigation.tabBarItem = [[[UITabBarItem alloc] autorelease] initWithTitle:@"车杂志" image:nil selectedImage:nil];
    [array addObject:journalNavigation];
    [journal release];
    [journalNavigation release];
    
    //创建新闻视图控制器
    NewsViewController *news = [[NewsViewController alloc] init];
    UINavigationController *newsNavigation = [[UINavigationController alloc] initWithRootViewController:news];
    newsNavigation.tabBarItem = [[[UITabBarItem alloc] autorelease] initWithTitle:@"车新闻" image:nil selectedImage:nil];
    [array addObject:newsNavigation];
    [news release];
    [newsNavigation release];
    
    //创建我的视图控制器
    MyViewController *my = [[MyViewController alloc] init];
    UINavigationController *myNavigation = [[UINavigationController alloc] initWithRootViewController:my];
    myNavigation.tabBarItem = [[[UITabBarItem alloc] autorelease] initWithTitle:@"更多" image:nil selectedImage:nil];
    [array addObject:myNavigation];
    [my release];
    [myNavigation release];
    
    //创建tabBarController
    UITabBarController *tabBar = [[UITabBarController alloc] init];
    tabBar.viewControllers = array;
    //设置tabBar为window根控制器
    self.window.rootViewController = tabBar;
    
    //设置所有导航栏的颜色
    [UINavigationBar appearance].barTintColor = [UIColor grayColor];
    //设置所以导航栏是否半透明
    [UINavigationBar appearance].translucent = NO;
    
    [tabBar release];
    [_window release];
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
